Page({
  data: {
    stats: {
      todayIncome: 288.50,
      todayOrders: 3,
      totalOrders: 128
    },
    pendingOrders: [
      {
        id: 1,
        customerName: '李先生',
        serviceName: '全身放松按摩',
        appointmentTime: '今天 14:00',
        address: '北京市朝阳区某某小区',
        price: 198
      },
      {
        id: 2,
        customerName: '王女士',
        serviceName: '足底按摩',
        appointmentTime: '今天 16:00',
        address: '北京市朝阳区某某大厦',
        price: 128
      }
    ]
  },

  onLoad: function() {
    this.loadTechnicianStats();
    this.loadPendingOrders();
  },

  loadTechnicianStats: function() {
    const app = getApp();
    
    app.request({
      url: `${app.globalData.baseUrl}/technician/stats/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            stats: res.data
          });
        }
      }
    });
  },

  loadPendingOrders: function() {
    const app = getApp();
    
    app.request({
      url: `${app.globalData.baseUrl}/technician/orders/pending/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            pendingOrders: res.data
          });
        }
      }
    });
  },

  goToOrderDetail: function(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/technician/orderDetail?id=${id}`
    });
  },

  goToOrderList: function() {
    wx.navigateTo({
      url: '/pages/technician/orderList'
    });
  },

  goToIncome: function() {
    wx.navigateTo({
      url: '/pages/technician/income'
    });
  },

  goToSettings: function() {
    wx.navigateTo({
      url: '/pages/technician/serviceSettings'
    });
  },

  goToProfile: function() {
    wx.navigateTo({
      url: '/pages/technician/profile'
    });
  }
})